package com.example.hospital.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.hospital.dto.MedicalrecordQuery;
import com.example.hospital.entity.Medicalrecord;
import com.example.hospital.service.MedicalrecordService;
import com.example.hospital.mapper.MedicalrecordMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Oreki
 * @description 针对表【medicalrecord】的数据库操作Service实现
 * @createDate 2024-12-27 16:53:20
 */
@Service
public class MedicalrecordServiceImpl extends ServiceImpl<MedicalrecordMapper, Medicalrecord>
        implements MedicalrecordService {

    @Override
    public List<Medicalrecord> listMedicalrecords(MedicalrecordQuery medicalrecordQuery) {
        if (medicalrecordQuery == null) {
            return list();
        }
        Integer patientId = medicalrecordQuery.getPatientId();
        Integer doctorId = medicalrecordQuery.getDoctorId();
        String startTime = medicalrecordQuery.getStartTime();
        String endTime = medicalrecordQuery.getEndTime();
        String diagnosis = medicalrecordQuery.getDiagnosis();
        String treatment = medicalrecordQuery.getTreatment();
        String type = medicalrecordQuery.getType();
        String allergicHistory = medicalrecordQuery.getAllergicHistory();
        String illnessHistory = medicalrecordQuery.getIllnessHistory();
        Integer isComplete = medicalrecordQuery.getIsComplete();
        String onsetDate = medicalrecordQuery.getOnsetDate();
        return lambdaQuery()
                .eq(patientId != null, Medicalrecord::getPatientId, patientId)
                .eq(doctorId != null, Medicalrecord::getDoctorId, doctorId)
                .ge(StrUtil.isNotEmpty(startTime), Medicalrecord::getVisitDate, startTime)
                .le(StrUtil.isNotEmpty(endTime), Medicalrecord::getVisitDate, endTime)
                .like(StrUtil.isNotEmpty(diagnosis), Medicalrecord::getDiagnosis, diagnosis)
                .like(StrUtil.isNotEmpty(treatment), Medicalrecord::getTreatment, treatment)
                .eq(StrUtil.isNotEmpty(type), Medicalrecord::getType, type)
                .like(StrUtil.isNotEmpty(allergicHistory), Medicalrecord::getAllergicHistory, allergicHistory)
                .like(StrUtil.isNotEmpty(illnessHistory), Medicalrecord::getIllnessHistory, illnessHistory)
                .eq(isComplete != null, Medicalrecord::getIsComplete, isComplete)
                .eq(StrUtil.isNotEmpty(onsetDate), Medicalrecord::getOnsetDate, onsetDate)
                .list();
    }
}




